local skel = fk.CreateSkill {
  name = "lb__xinshi",
}

Fk:loadTranslationTable {
  ["lb__xinshi"] = "心蚀",
  [":lb__xinshi"] = "每回合限一次，当你受到伤害后，你可以对伤害来源造成1点雷电伤害，其下个回合不能对你使用非黑色牌，然后你获得<a href=':lb__yuekuang'><font color='red'>〖月狂〗</font></a>直到下回合结束。",

  ["#lb__xinshi"] = "心蚀：你可以对%dest造成1点雷电伤害，其下个回合不能对你使用非黑色牌，然后你获得〖月狂〗直到你下个回合结束",
  ["@@lb__xinshi_delay"] = "心蚀",
  ["@@lb__xinshi-turn"] = "<font color='red'>心蚀</font>",

  ["$lb__xinshi1"] = "是你一心求死！",
  ["$lb__xinshi2"] = "以汝之血，砥砺牙爪！",
}

skel:addEffect(fk.Damaged, {
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and data.from and data.from:isAlive()
        and player:usedSkillTimes(skel.name, Player.HistoryTurn) == 0
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, { skill_name = skel.name, prompt = "#lb__xinshi::" .. data.from.id, })
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:damage {
      from = player,
      to = data.from,
      damage = 1,
      damageType = fk.ThunderDamage,
      skillName = skel.name,
    }
    if data.from:isAlive() then
      room:setPlayerMark(data.from, "@@lb__xinshi_delay", tostring(player.id))
    end
    if not player:hasSkill("lb__yuekuang", true) then
      room:setPlayerMark(player, skel.name, 1)
      room:handleAddLoseSkills(player, "lb__yuekuang")
    end
  end,
})

skel:addEffect(fk.TurnStart, {
  can_refresh = function(self, event, target, player, data)
    return target == player and (player:getMark(skel.name) > 0 or player:getMark("@@lb__xinshi_delay") ~= 0)
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if player:getMark(skel.name) > 0 then
      room:setPlayerMark(player, skel.name, 0)
      local Turn = room.logic:getCurrentEvent()
      if Turn then
        Turn:addCleaner(function()
          if player:hasSkill("lb__yuekuang", true) then
            room:handleAddLoseSkills(player, "-lb__yuekuang")
          end
        end)
      end
    end
    if player:getMark("@@lb__xinshi_delay") ~= 0 then
      room:setPlayerMark(player, "@@lb__xinshi-turn", player:getMark("@@lb__xinshi_delay"))
      room:setPlayerMark(player, "@@lb__xinshi_delay", 0)
    end
  end,
})

skel:addEffect("prohibit", {
  is_prohibited = function(self, from, to, card)
    return card.color ~= Card.Black and from and from:getMark("@@lb__xinshi-turn") == tostring(to.id)
  end,
})

return skel